﻿using EasyDDD.Domain;
using EasyDDD.Domain.User;
using Microsoft.EntityFrameworkCore;
using System.ComponentModel.DataAnnotations.Schema;
using System.Text.Json.Serialization;

namespace EasyDDD.AdminModule.Domain.AggregateSysAdmin
{
    /// <summary>
    /// 后台管理员
    /// </summary>
    //public record SysAdminId(Guid Value) : Key<Guid>(Value);
    //[Table(nameof(SysAdmin))]
    public class SysAdmin : ApplicationUser, IAggregateRoot
    {
        [JsonConstructor]
        protected SysAdmin() { }

        #region 方法
        public override void Add()
        {
            if (this.Id != Guid.Empty)
            {
                throw new InvalidOperationException($"该实体{this.GetType().Name}:{this.Id}已创建！");
            }

            if (string.IsNullOrEmpty(UserName)) throw new ArgumentNullException("UserName不能为空");
            if (string.IsNullOrEmpty(PasswordHash)) throw new ArgumentNullException("PasswordHash不能为空");

            NormalizedUserName = UserName.ToUpper();
            NormalizedEmail = Email.ToUpper();

            this.SetPassword(this.PasswordHash);
        }
        #endregion
    }
}
